package com.efuture.chapterfive

/* @Description: 密封类学习
 * @Auther: zhaoshanshan
 * @Date: 2022/03/07/4:03 下午
 */
//密封类 关键字 sealed 该类成员必须有类型 并且继承本类
sealed class Exam{
    object Fraction1:Exam()
    object Fraction2:Exam()
    object Fraction3:Exam()
    class Fraction4(val name:String):Exam()
}
class Teacher(private val exam:Exam){
    fun show():String{
        return when(exam){
            is Exam.Fraction1->"分数很差"
            is Exam.Fraction2->"分数及格"
            is Exam.Fraction3->"分数良好"
            is Exam.Fraction4->"该学生分数优秀,学生姓名是${(this.exam as Exam.Fraction4).name}"
        }

    }
}
fun main() {
    println(Teacher(Exam.Fraction1).show())
    println(Teacher(Exam.Fraction2).show())
    println(Teacher(Exam.Fraction3).show())
    println(Teacher(Exam.Fraction4("赵山山")).show())
}
    